from sqlalchemy import Column, Integer, String, DateTime, Boolean
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime

Base = declarative_base()


class User(Base):
    """用户模型"""
    __tablename__ = "users"
    
    id = Column(Integer, primary_key=True, index=True)
    username = Column(String(100), unique=True, index=True, nullable=True)
    nickname = Column(String(100), nullable=True)  # 钉钉昵称
    mobile = Column(String(20), unique=True, index=True, nullable=True)
    email = Column(String(100), nullable=True)
    avatar = Column(String(500), nullable=True)  # 头像URL
    dingtalk_id = Column(String(100), unique=True, index=True, nullable=True)  # 钉钉openid
    unionid = Column(String(100), nullable=True)  # 钉钉unionid
    corp_id = Column(String(100), nullable=True)  # 组织ID
    is_active = Column(Boolean, default=True)
    created_at = Column(DateTime, default=datetime.now)
    updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)

